package com.ymt.fmd.platform.web.rest;

import java.util.Map;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import com.ymt.fmd.platform.service.PopupPageService;
import com.ymt.fmd.util.Const;

@Component
@Path("/popup")
public class PopupResource {

	private static Logger logger = Logger.getLogger(PopupResource.class.getName());
	
	@Autowired
	private PopupPageService ppService;
	
	@Context
	private HttpServletRequest request;
	
    @POST
	@Path("queryUrl")
    @Produces({ "application/json" })
	public String fingAllUrl(@FormParam("ordercolumns")String ordercolumns,
			@FormParam("fromRow")int fromRow,
			@FormParam("toRow")int toRow,
			@FormParam("timezoneOffset")int timezoneOffset){
		Map<String, String> userDetail = (Map<String, String>) SecurityContextHolder.getContext().getAuthentication().getDetails();
    	String lang = userDetail.get(Const.LANG);
		String tenantId = userDetail.get(Const.TENANT_ID);
		logger.finer("fingAllUrl lang="+lang);
		logger.finer("fingAllUrl tenantId="+tenantId);
		logger.finer("fingAllUrl ordercolumns="+ordercolumns);
		logger.finer("fingAllUrl fromRow="+fromRow);
		logger.finer("fingAllUrl toRow="+toRow);
		logger.finer("fingAllUrl timezoneOffset="+timezoneOffset);
		return ppService.findPopupUrl(tenantId, fromRow, toRow, timezoneOffset, lang, ordercolumns);
	}
}
